//
//  cgxxViewController.m
//  BAOASystem
//
//  Created by michael on 2018/5/30.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "cgxxViewController.h"
#import "LZPickerView.h"

@interface cgxxViewController ()
@property(nonatomic,strong)LZPickerView *lzPickerVIew;

@end

@implementation cgxxViewController

- (void)viewDidLoad {
    [super viewDidLoad];
      NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"LZPickerView" owner:nil options:nil];
    self.lzPickerVIew  = views[0];
     NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 self.view.backgroundColor = [UIColor whiteColor];

[self.navigationController.navigationBar setTitleTextAttributes:attributes];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0a62ea"];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
          self.navigationController.navigationBar.hidden = NO;
    // Do any additional setup after loading the view.
//        [self initview];
 _indexPathup = [NSMutableArray array];
    _indexPathdowm = [NSMutableArray array];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[_indexPathup addObject:dic];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[_indexPathdowm addObject:dict];
    [self loaddata];

}
 -(void)loaddata{
 
  [MBProgressHUD showHUDAddedTo:self.view animated:YES];

NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];

   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
     if (_ipid.length==0) {
    _ipid = @"";
}

NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>%@</userName><password>%@</password><website>%@</website><language>%@</language><type>%@</type></header><body><id>%@</id></body></message>",userName,password,website,language,BAtype,_ipid];
 bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bDemandList];
 [HttpTools requestWithURL:path arrays:array method:@"toDemandPage" success:^(id JSON) {
   [MBProgressHUD hideHUDForView:self.view animated:YES];
   NSLog(@"%@",JSON);
   if ([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"]){
   if ([[NSString stringWithFormat:@"%@",JSON[@"aouDemand"]]isEqualToString:@"update"]) {

      NSDictionary *dic = JSON[@"demand"];
         _titlename =dic[@"title"];
            _keywords = dic[@"keyword"];
   _selCategoryName = JSON[@"selCategoryName"];
   _remark = dic[@"remark"];
_isPrice = dic[@"isPrice"];
_istype = dic[@"type"];
_validity =dic[@"validity"];
_selYxqName =JSON[@"selYxqName"];
_selJlName = JSON[@"selJlName"];
   NSArray *uparray = JSON[@"DemandAttribute"];
 if (uparray != nil && ![uparray isKindOfClass:[NSNull class]] && uparray.count != 0) {
    _indexPathup = [uparray mutableCopy];
}
   NSArray *downarray = JSON[@"DemandPrice"];
 if (downarray != nil && ![downarray isKindOfClass:[NSNull class]] && downarray.count != 0) {
    _indexPathdowm = [downarray mutableCopy];
}
   
   }
   
 _dic = JSON;
    [self initview];
    
}else{
    [self.view makeToast:JSON[@"msg"]];
}
 } failure:^(NSError *error) {
  [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];

 }
- (void)initview{
if(!_tableView){
 _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,KScreenHeight-kTopHeight) style:UITableViewStylePlain];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.bounces = NO;
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 3;
            break;
        case 1:
            return self.indexPathup.count;
       
        case 2:
            return self.indexPathdowm.count;
        case 3:
            return 4;
        default:
            return 1;
            break;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section ==0) {
if (indexPath.row ==0) {
    static NSString *cellid00 = @"cellid00";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid00];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid00];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

        UILabel *label0 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 30)];
  label0.textColor = [UIColor colorWithHexString:@"0a62ea"];
    label0.text = NSLocalizedString(@"基本信息", nil);
 [cell.contentView addSubview:label0];
UIView *bomview = [[UIView alloc]initWithFrame:CGRectMake(0, 29, KScreenWidth, 1)];
bomview.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];
[cell.contentView addSubview:bomview];
 NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-商品名称", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, label0.bottom,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 _shangpinname = [[zhucetextfield alloc]init];
              _shangpinname.delegate = self;
    if(_titlename.length>0){
    _shangpinname.text = _titlename;
    }
 _shangpinname.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
// _shangpinname.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
//      _shangpinname.keyboardType = UIKeyboardTypeASCIICapable;
             [cell.contentView addSubview:_shangpinname];
    }
 
        return cell;

}else if (indexPath.row ==1) {
  static NSString *cellid01 = @"cellid01";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid01];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid01];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

         NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*采购关键词", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 _shangpinkey = [[zhucetextfield alloc]init];
  _shangpinkey.delegate = self;
  
   if(_keywords.length>0){
    _shangpinkey.text = _keywords;
    }
 _shangpinkey.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
 [cell.contentView addSubview:_shangpinkey];
  
    }


        return cell;

}else if (indexPath.row ==2){
static NSString *cellid02 = @"cellid02";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid02];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid02];
       cell.selectionStyle = UITableViewCellSelectionStyleNone;

   NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*采购类目", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 _leimubutton = [zhucebutton buttonWithType:UIButtonTypeCustom];
      _leimubutton.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
//       [_leimubutton setImage:[UIImage imageNamed:@"下拉"] forState:UIControlStateNormal];
//_leimubutton.titleEdgeInsets = UIEdgeInsetsMake(0,0, 0, 50);
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-50,10 , 20, 20)];
image.image = [UIImage imageNamed:@"下拉"];
[_leimubutton addSubview:image];
  if(_selCategoryName.length>0){
[_leimubutton setTitle:_selCategoryName forState:UIControlStateNormal];    }
[_leimubutton addTarget:self action:@selector(leimuaction) forControlEvents:UIControlEventTouchUpInside];
//       [_leimubutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight
//                                    imageTitleSpace:KScreenWidth-80];
   [cell.contentView addSubview:_leimubutton];
 }
 
return cell;
}

else{
return nil;

}
}else if(indexPath.section ==1){

static NSString *cellid10 = @"cellid10";
    addvaluesTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid10];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[addvaluesTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid10];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    cell.dic = _indexPathup[indexPath.row];
        return cell;

}else if(indexPath.section ==2){

static NSString *cellid30 = @"cellid30";
    addpriceTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid30];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[addpriceTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid30];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else{
if(indexPath.row==0){
static NSString *cellid0 = @"cellid0";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid0];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

  
      NSString *string2 =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*采购单位", nil)];
   NSMutableAttributedString *attrStr2 = [[NSMutableAttributedString alloc] initWithString:string2];
      [attrStr2 addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label2.textColor = [UIColor colorWithHexString:@"484848"];
//label.text = string;
label2.attributedText = attrStr2;
    label2.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label2];
            _danweibutton = [zhucebutton buttonWithType:UIButtonTypeCustom];

      _danweibutton.frame = CGRectMake(10, label2.bottom, (KScreenWidth-20), 40);
//       [_comstartbutton setImage:[UIImage imageNamed:@"日期"] forState:UIControlStateNormal];
//       [_comstartbutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight
//                                    imageTitleSpace:(KScreenWidth- 60)];
  if(_selJlName.length>0){
[_danweibutton setTitle:_selJlName forState:UIControlStateNormal];    }
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-50,10 , 20, 20)];
image.image = [UIImage imageNamed:@"下拉"];
[_danweibutton addSubview:image];
[_danweibutton addTarget:self action:@selector(danweiction) forControlEvents:UIControlEventTouchUpInside];
   [cell.contentView addSubview:_danweibutton];
    
        }
        return cell;
    
}
else if(indexPath.row==1){
static NSString *cellid05 = @"cellid05";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid05];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid05];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

         UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5,40, 20)];
   NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*类型", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
  [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
 label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText =attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    _leixingbox = [leixing checkBoxFootView];
    _istype = [NSString stringWithFormat:@"%@",_istype];
     [_leixingbox setSelectRowBlock:^(NSString *rowTitle) {
    _istype = rowTitle;

}];

if ([_istype isEqualToString:@"1"]) {
        _leixingbox.seltag = 1;

}else if([_istype isEqualToString:@"0"]){
    _leixingbox.seltag = 0;

}else{
    _leixingbox.seltag = 2;

}
     _leixingbox.frame = CGRectMake(label.right, 5,KScreenWidth-20-50-100, 20);
             [cell.contentView addSubview:_leixingbox];
      NSString *string2 =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*有效期", nil)];
   NSMutableAttributedString *attrStr2 = [[NSMutableAttributedString alloc] initWithString:string2];
      [attrStr2 addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 30,KScreenWidth-20, 20)];
  label2.textColor = [UIColor colorWithHexString:@"484848"];
//label.text = string;
label2.attributedText = attrStr2;
    label2.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label2];
            _comstartbutton = [zhucebutton buttonWithType:UIButtonTypeCustom];

      _comstartbutton.frame = CGRectMake(10, label2.bottom, (KScreenWidth-20), 40);
//       [_comstartbutton setImage:[UIImage imageNamed:@"日期"] forState:UIControlStateNormal];
//       [_comstartbutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight
//                                    imageTitleSpace:(KScreenWidth- 60)];
  if(_selYxqName.length>0){
[_comstartbutton setTitle:_selYxqName forState:UIControlStateNormal];    }
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-50,10 , 20, 20)];
image.image = [UIImage imageNamed:@"下拉"];
[_comstartbutton addSubview:image];
[_comstartbutton addTarget:self action:@selector(setupaction) forControlEvents:UIControlEventTouchUpInside];
   [cell.contentView addSubview:_comstartbutton];
    
        }
        return cell;
    
}
else if(indexPath.row==2){
 static NSString *cellid25 = @"cellid25";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid25];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid25];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

     NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*描述", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
//label.text = string;
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    
    _miaoshufield = [[UITextView alloc]init];
              _miaoshufield.delegate = self;
    _miaoshufield.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 80);
  _miaoshufield.layer.cornerRadius=8.0f;
   _miaoshufield.layer.masksToBounds=YES;
    _miaoshufield.layer.borderColor=[[UIColor grayColor]CGColor];
    _miaoshufield.layer.borderWidth= 1.0f;
          [cell.contentView addSubview:_miaoshufield]; }
 
   if(_remark.length>0){
    _miaoshufield.text = _remark;
    }
  
return cell;
}else{
     static NSString *CellIdentifier2 = @"Cellbendititlepic2";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
//        cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
      button.frame = CGRectMake(20, 10, KScreenWidth-40, 40);
button.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

    [button setTitle:NSLocalizedString(@"提交", nil) forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
        button.layer.cornerRadius = button.height/2;
        [button addTarget:self action:@selector(baocunaction) forControlEvents:UIControlEventTouchUpInside];
    
[cell.contentView addSubview:button];
    return cell;
    
  
    }

}

}
- (void)baocunaction{
   _titlename = [_shangpinname.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   _keywords= [_shangpinkey.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   _remark= [_miaoshufield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   NSDictionary*dic = _indexPathup[0];
  NSString *name =[NSString stringWithFormat:@"%@",dic[@"name"]];
    
NSString *values =[NSString stringWithFormat:@"%@",dic[@"values"]];
 name =    [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 values =   [values stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 NSString *startNum = [NSString string];
  NSString *endNum = [NSString string];
  NSString *price = [NSString string];
if ([_fanweibox.orderString isEqualToString:@"1"]){
     NSDictionary*dict = _indexPathdowm[0];
    startNum =[NSString stringWithFormat:@"%@",dict[@"startNum"]];
    
endNum =[NSString stringWithFormat:@"%@",dict[@"endNum"]];
price =[NSString stringWithFormat:@"%@",dict[@"price"]];
 startNum =    [startNum stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 endNum =   [endNum stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   price =  [price stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 }
if ([_titlename isEqualToString:@""]|| _titlename.length == 0){
     [self.view makeToast:NSLocalizedString(@"添加商品-商品名称为空", nil)];
}
else if ([_keywords isEqualToString:@""]|| _keywords.length == 0){
     [self.view makeToast:NSLocalizedString(@"采购关键字为空", nil)];
}else if ([_selCategoryName isEqualToString:@""]|| _selCategoryName.length == 0){
     [self.view makeToast:NSLocalizedString(@"采购类目为空", nil)];
}else if ([_selJlName isEqualToString:@""]|| _selJlName.length == 0){
     [self.view makeToast:NSLocalizedString(@"采购单位为空", nil)];
}else if ([_selYxqName isEqualToString:@""]|| _selYxqName.length == 0){
     [self.view makeToast:NSLocalizedString(@"有效期为空", nil)];
}else if ([_remark isEqualToString:@""]|| _remark.length == 0){
     [self.view makeToast:NSLocalizedString(@"描述为空", nil)];
}else if(name.length ==0 ||values.length ==0 ||[name isEqualToString:@"(null)"]||[values isEqualToString:@"(null)"])
{
      [self.view makeToast:NSLocalizedString(@"采购属性为空", nil)];

}else if ([_fanweibox.orderString isEqualToString:@"1"]&&(startNum.length ==0 ||endNum.length ==0 ||price.length ==0||[startNum isEqualToString:@"(null)"]||[endNum isEqualToString:@"(null)"]||[price isEqualToString:@"(null)"])){

    

    [self.view makeToast:NSLocalizedString(@"注册信息-自定义价格区间为空", nil)];



}


else{
NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
   NSString *uid = [[NSUserDefaults standardUserDefaults] objectForKey:@"uid"];
      NSString *cpid = [[NSUserDefaults standardUserDefaults] objectForKey:@"cpid"];


 if (_ipid.length==0) {
    _ipid = @"";

}
NSString *Productstr = [NSString string];
for (int i = 0; i<_indexPathup.count; i++) {

 NSString*   name = [NSString stringWithFormat:@"<name>%@</name>",_indexPathup[i][@"name"]];
    NSString*   values = [NSString stringWithFormat:@"<values>%@</values>",_indexPathup[i][@"values"]];
   NSString *Productstring = [NSString stringWithFormat:@"<DemandAttribute>%@%@</DemandAttribute>",name,values];
Productstr = [Productstr stringByAppendingString:Productstring];


}
 Productstr = [NSString stringWithFormat:@"<DemandAttributes>%@</DemandAttributes>",Productstr];
NSString *pricestr = [NSString string];
if ([_isPrice isEqualToString:@"0"]) {
    pricestr = @"";
}else{
for (int i = 0; i<_indexPathdowm.count; i++) {
    NSString*   startNum = [NSString stringWithFormat:@"<startNum>%@</startNum>",_indexPathdowm[i][@"startNum"]];
    NSString*   endNum = [NSString stringWithFormat:@"<endNum>%@</endNum>",_indexPathdowm[i][@"endNum"]];
        NSString*   price = [NSString stringWithFormat:@"<price>%@</price>",_indexPathdowm[i][@"price"]];

   NSString *namestring = [NSString stringWithFormat:@"<DemandPrice>%@%@%@</DemandPrice>",startNum,endNum,price];
pricestr = [pricestr stringByAppendingString:namestring];
}
 pricestr = [NSString stringWithFormat:@"<DemandPrices>%@</DemandPrices>",pricestr];

}

NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>%@</userName><password>%@</password><website>%@</website><language>%@</language><type>%@</type></header><body><Demand><id>%@</id><title>%@</title><type>%@</type><keyword>%@</keyword><categoryId>%@</categoryId><validity>%@</validity><remark>%@</remark><countUnit>%@</countUnit><isPrice>%@</isPrice><userId>%@</userId><cpid>%@</cpid></Demand>%@%@</body></message>",userName,password,website,language,BAtype,_ipid,_titlename,_istype,_keywords,_leimuid,_validity,_remark,_countUnit,_isPrice,uid,cpid,Productstr,pricestr];
bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bDemandList];
 [HttpTools requestWithURL:path arrays:array method:@"demandSave" success:^(id JSON) {
    NSLog(@"%@",JSON);


         [self.view makeToast:JSON[@"msg"]];

//                        [NSThread sleepForTimeInterval:1.0];

if([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"]){

[self performSelector: @selector(popaction) withObject: nil afterDelay:1.0f];
}

 }failure:^(NSError *error) {
  [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];
    }


}
 -(void)popaction{
             [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshData" object:nil]; //刷新发件箱，收件箱 数据

 [self.navigationController popViewControllerAnimated:YES];
 }
- (void)danweiction{
NSArray *array = _dic[@"jldictlist"];
NSMutableArray *muaarray = [NSMutableArray array];
for (NSDictionary *dic in array) {
    [muaarray addObject:dic[@"dictname"]];
}
[self.lzPickerVIew lzPickerVIewType:LZPickerViewTypeSexAndHeight];
self.lzPickerVIew.dataSource =muaarray;
    [self.lzPickerVIew show];
  __weak typeof(self) weakSelf = self;
          self.lzPickerVIew.selectValue  = ^(NSString *value){

                 [weakSelf.danweibutton setTitle:value forState:UIControlStateNormal];
      _selJlName = value;
     for (NSDictionary *dic in array) {
   
   if ([value isEqualToString:dic[@"dictname"]]) {
   _countUnit = dic[@"id"];
}
}
    };

}
- (void)setupaction{
NSArray *array = _dic[@"yxqlist"];
NSMutableArray *muaarray = [NSMutableArray array];
for (NSDictionary *dic in array) {
    [muaarray addObject:dic[@"dictname"]];
}
[self.lzPickerVIew lzPickerVIewType:LZPickerViewTypeSexAndHeight];
self.lzPickerVIew.dataSource =muaarray;
    [self.lzPickerVIew show];
  __weak typeof(self) weakSelf = self;
          self.lzPickerVIew.selectValue  = ^(NSString *value){

                 [weakSelf.comstartbutton setTitle:value forState:UIControlStateNormal];
      _selYxqName = value;
     for (NSDictionary *dic in array) {
   
   if ([value isEqualToString:dic[@"dictname"]]) {
   _validity = dic[@"id"];
}
}
    };

}
- (NSString *)dateStringWithDate:(NSDate *)date DateFormat:(NSString *)dateFormat
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:dateFormat];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    NSString *str = [dateFormatter stringFromDate:date];
    return str ? str : @"";
}
- (void)addaction:(UIButton *)btn{
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[_indexPathup addObject:dic];
//[_tableView reloadData];
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1]; //你需要更新的组数
[_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];  //collection 相同
}
- (void)addpriceaction:(UIButton *)btn{

if ([_fanweibox.orderString isEqualToString:@"1"]){
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[_indexPathdowm addObject:dic];
//[_tableView reloadData];
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; //你需要更新的组数
[_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
} //collection 相同
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
 if (section==1) {
 UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
         bgView.backgroundColor = [UIColor whiteColor];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
  NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*采购属性", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:label];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(KScreenWidth-120, 5, 80, 20);
    button.titleLabel.font = [UIFont systemFontOfSize: 14.0];
button.backgroundColor = [UIColor colorWithHexString:@"0aa0f6"];
[button setImage:[UIImage imageNamed:@"添加"] forState:UIControlStateNormal];
[button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:0];
[button setTitle:NSLocalizedString(@"添加商品-添加属性", nil) forState:UIControlStateNormal];
    button.layer.masksToBounds=YES;
                   button.layer.cornerRadius=2.0f;
   [button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
[button addTarget:self action:@selector(addaction:) forControlEvents:UIControlEventTouchUpInside];
[bgView addSubview:button];
     
return bgView;
 }
 else if (section==2) {
// _isPrice = @"1";
 UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
         bgView.backgroundColor = [UIColor whiteColor];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5,40, 20)];
   NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-价格", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
  [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
 label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText =attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:label];
       _fanweibox = [fanweibox checkBoxFootView];

    [_fanweibox setSelectRowBlock:^(NSString *rowTitle) {
    _isPrice = rowTitle;

}];
    if ([_fanweibox.orderString isEqualToString:@"1"]) {
    _isPrice = @"1";
}

if ([_isPrice isEqualToString:@"1"]) {
        _fanweibox.seltag = 1;

}else{
    _fanweibox.seltag = 0;

}
 _fanweibox.frame = CGRectMake(label.right, 5,KScreenWidth-20-50-100, 20);
             [bgView addSubview:_fanweibox];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(KScreenWidth-110, 5, 100, 20);
    button.titleLabel.font = [UIFont systemFontOfSize: 14.0];
button.backgroundColor = [UIColor colorWithHexString:@"0aa0f6"];
[button setImage:[UIImage imageNamed:@"添加"] forState:UIControlStateNormal];
[button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:0];
[button setTitle:NSLocalizedString(@"添加商品-增加价格区间", nil) forState:UIControlStateNormal];
    button.layer.masksToBounds=YES;
                   button.layer.cornerRadius=2.0f;
   [button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
[button addTarget:self action:@selector(addpriceaction:) forControlEvents:UIControlEventTouchUpInside];
[bgView addSubview:button];
     
return bgView;
 }
 else{
 return nil;
 }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==1) {
        return 30;
    } else
    if (section==2) {
        return 30;
    }
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

if(indexPath.section==0){
if(indexPath.row ==0)
{
return 90;
}else {
return 60;


}
}if(indexPath.section==1){
 return 50;


}if(indexPath.section==2){
 return 50;
}else{
 if(indexPath.row ==0)
{
return 60;
}
else if(indexPath.row ==1)
{
return 90;
}
 return 100;

}
}
- (void)leimuaction{
threelevelViewController *vc = [[threelevelViewController alloc]init];
vc.hidesBottomBarWhenPushed = YES;
vc.type = @"shangpin";
[vc setSelectRowBlock:^(NSString *rowTitle, NSString *ipid) {
[_leimubutton setTitle:rowTitle forState:UIControlStateNormal];
_selCategoryName = rowTitle;
_leimuid = ipid;
[_tableView reloadData];
}];
[self.navigationController pushViewController:vc animated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
